package com.taru.order.service;

import com.taru.order.common.Data;
import com.taru.order.dao.AnswerDaoImpl;
import com.taru.order.dao.ProblemDaoImpl;
import com.taru.order.dao.UserDaoimpl;
import com.taru.order.entity.Answer;
import com.taru.order.entity.Problem;
import com.taru.order.entity.User;

import java.util.List;

public class ProblemServiceImpl {

    ProblemDaoImpl problemDao=new ProblemDaoImpl();
    AnswerDaoImpl answerDao=new AnswerDaoImpl();
    /**
     * 添加问题
     */
    public int addProblem(Problem problem){

        return problemDao.addProblem(problem);
    }
    /**
     * 获取最新的问题（列表）
     */
    public Data listProblem(Integer pageNum, Integer pageSize){
        ProblemDaoImpl problemDao1=new ProblemDaoImpl();
        List<Problem> list=problemDao1.listProblem(pageNum,pageSize);
        Long toralCount=problemDao1.queryToral();
        Data data=new Data();
        data.setTotalCount(toralCount);
        data.setTotalPage(toralCount,pageSize);
        data.setPageNum(pageNum);
        data.setPageSize(pageSize);
        data.setList(list);
        return data;

    }
    /**
     * 修改问题
     */
    public int modProblem(Problem problem){

        return problemDao.modProblem(problem);
    }
    /**
     * 删除问题
     */
    public int deleteProblems(List list) throws Exception {

        return problemDao.deleteProblem(list);
    }
    /**
     * 获取问题详情（根据问题id，附带答案）
     */
    public Problem getProblem(String id){
        List<Answer> list=answerDao.listAnswer(id);
        Problem problem=problemDao.getProblem(id);
        problem.setAnswers(list);
        return problem;
    }
}
